#!/usr/local/bin/node

var url = process.argv[2],
db_name = process.argv[3],
id = process.argv[4],
how_many = process.argv[5];
var db = require('nano')(url).use(db_name);
var all_docs = new Array;

var sitios = ['Gasolinera', 'Puticlú', 'Restaurante', 'Farmacia', 'Hotel', 'Parking'];
var nombres = new Array;
        nombres[0] = 'Juan';
        nombres[1] = 'Raul';
        nombres[2] = 'Rosa';
        nombres[3] = 'María';
        nombres[4] = 'Azucena';

for ( var j = 0; j < how_many; j ++ ) {
    var doc = new Object;
    doc._id = id+"_"+j; 
    doc.nombre = nombres[Math.floor(Math.random()*5)];
    doc.coord_X = (Math.random()*90);
    doc.coord_Y = (Math.random()*90);
    doc.paradas = new Array;
    for ( var i = 0; i < 5; i++ ) {
        doc.paradas[i] = sitios[Math.floor(Math.random()*5)];
    }
    console.log( doc );
    all_docs.push( doc );
}

console.log(all_docs);
db.bulk( { 'docs' : all_docs},
         function (error,http_body,http_headers) {
             console.log(http_body);
         }
       );